package com.example.server.service.admin.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.server.common.constant.Result;
import com.example.server.entity.Button;
import com.example.server.mapper.ButtonMapper;
import com.example.server.service.admin.ButtonService;
import com.example.server.vo.ButtonVO;
import com.example.server.vo.MenuVO;
import org.springframework.stereotype.Service;

/**
 * @author china.fuyao@outlook.com
 * @date 2020-04-19 15:34
 */
@Service("buttonService")
public class ButtonServiceImpl extends ServiceImpl<ButtonMapper, Button> implements ButtonService {
    /**
     * 新增按钮
     *
     * @param buttonVO
     * @param customerId
     * @return
     */
    @Override
    public Result addButton(ButtonVO buttonVO, Integer customerId) {
        Button button = new Button();
        button.setBtnName(buttonVO.getBtnName());
        button.setBtnType(buttonVO.getBtnType());
        button.setBtnIcon(buttonVO.getBtnIcon());
        button.setBtnColor(buttonVO.getBtnColor());
        button.setSort(buttonVO.getSort());
        button.setStatus(buttonVO.getStatus());
        boolean save = save(button);
        if (save) {
            return Result.OK();
        }
        return Result.Error();
    }

    /**
     * 修改按钮
     *
     * @param buttonVO
     * @param customerId
     * @return
     */
    @Override
    public Result updateButton(ButtonVO buttonVO, Integer customerId) {
        if (null == buttonVO || null == buttonVO.getBtnId()) {
            return Result.Error("请求参数异常");
        }
        Button button = getById(buttonVO.getBtnId());
        button.setBtnName(buttonVO.getBtnName());
        button.setBtnType(buttonVO.getBtnType());
        button.setBtnIcon(buttonVO.getBtnIcon());
        button.setBtnColor(buttonVO.getBtnColor());
        button.setSort(buttonVO.getSort());
        button.setStatus(buttonVO.getStatus());
        boolean update = updateById(button);
        if (update) {
            return Result.OK();
        }
        return Result.Error();
    }

    /**
     * 删除按钮
     *
     * @param buttonId
     * @param customerId
     * @return
     */
    @Override
    public Result delButton(Integer buttonId, Integer customerId) {
        boolean remove = removeById(buttonId);
        if (remove) {
            return Result.OK();
        }
        return Result.Error();
    }
}
